﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using Eneta.Portal.Common.Repository;

using Microsoft.SharePoint;

namespace Eneta.Portal.Admin.Controls
{
    public class AdminBlogListControl : UserControl
    {
        protected Repeater BlogsRepeater;
        protected Label NoBlogsLabel;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var repository = new BlogRepository(SPContext.Current.Web);
            var blogs = repository.GetPendingBlogs();

            BlogsRepeater.Visible = false;
            NoBlogsLabel.Visible = false;

            if (blogs != null && blogs.Count > 0)
            {
                BlogsRepeater.DataSource = blogs;
                BlogsRepeater.DataBind();
                BlogsRepeater.Visible = true;
            }
            else
            {
                NoBlogsLabel.Visible = true;
            }
        }
    }
}
